home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 176-200 / disk_195 / microemacs / src.zoo / hp150.c < prev    next >
C/C++ Source or Header  |  1989-03-23  |  10KB  |  479 lines

  1. /*
  2.  * The routines in this file provide support for HP150 screens
  3.  * and routines to access the Keyboard through KEYCODE mode.
  4.  * It compiles into nothing if not an HP150 screen device.
  5.  * added by Daniel Lawrence
  6.  */
  7.  
  8. #define    termdef    1            /* don't define "term" external */
  9.  
  10. #include        <stdio.h>
  11. #include        "estruct.h"
  12. #include    "etype.h"
  13. #include    "edef.h"
  14. #include    "elang.h"
  15.  
  16. #if     HP150
  17.  
  18. #define NROW    24                      /* Screen size.                 */
  19. #define NCOL    80                      /* Edit if you want to.         */
  20. #define    MARGIN    8            /* size of minimim margin and    */
  21. #define    SCRSIZ    64            /* scroll size for extended lines */
  22. #define    NPAUSE    15            /* # times thru update to pause */
  23. #define BEL     0x07                    /* BEL character.               */
  24. #define ESC     0x1B                    /* ESC character.               */
  25.  
  26. extern int PASCAL NEAR  openhp();    /* Forward references.          */
  27. extern int PASCAL NEAR    hpflush();
  28. extern int PASCAL NEAR  closehp();
  29. extern int PASCAL NEAR    hp15kopen();
  30. extern int PASCAL NEAR    hp15kclose();
  31. extern int PASCAL NEAR  hp15move();
  32. extern int PASCAL NEAR  hp15eeol();
  33. extern int PASCAL NEAR  hp15eeop();
  34. extern int PASCAL NEAR  hp15beep();
  35. extern int PASCAL NEAR    gethpkey();
  36. extern int PASCAL NEAR    hp15rev();
  37. extern int PASCAL NEAR    hp15cres();
  38. #if    COLOR
  39. extern int PASCAL NEAR    hp15fcol();
  40. extern int PASCAL NEAR    hp15bcol();
  41. #endif
  42.  
  43. PASCAL NEAR hp15parm();
  44. PASCAL NEAR rawon();
  45. PASCAL NEAR rawoff();
  46. PASCAL NEAR ckeyoff();
  47. PASCAL NEAR ckeyon();
  48. PASCAL NEAR agios();
  49. PASCAL NEAR keycon();
  50. PASCAL NEAR keycoff();
  51. PASCAL NEAR defkey();
  52. PASCAL NEAR undefkey();
  53. PASCAL NEAR dsplbls();
  54.  
  55. /* weird to ascii translation table */
  56.  
  57. char trans[][2] = {
  58.     0x24,    9,    /* tab */
  59.     0x25,    13,    /* ret */
  60.     0x27,    8,    /* backspace */
  61.     0x30,    48,    /* zero */
  62.     0x31,    49,    /* one */
  63.     0x32,    50,    /* two */
  64.     0x33,    51,    /* three */
  65.     0x34,    52,    /* four */
  66.     0x35,    53,    /* five */
  67.     0x36,    54,    /* six */
  68.     0x37,    55,    /* seven */
  69.     0x38,    56,    /* eight */
  70.     0x39,    57,    /* nine */
  71.     0x50,    13,    /* enter */
  72.     0x54,    27,    /* break -> ESC */
  73.     0x55,    27,    /* esc */
  74.     0x58,    24,    /* stop -> ^X */
  75.     0x70,    45,    /* N-minus */
  76.     0x71,    42,    /* N-asterisk */
  77.     0x72,    43,    /* N-plus */
  78.     0x73,    47,    /* N-slash */
  79.     0x74,    44,    /* N-comma */
  80.     0x75,    13,    /* N-enter */
  81.     0x76,    9,    /* N-tab */
  82.     0x77,    46    /* N-period */
  83. };
  84.  
  85. #define NTRANS    sizeof(trans) / 2
  86.  
  87. union REGS r;        /* register set for bios and dos (AGIOS) calls */
  88. int capslock = 0;    /* caps lock flag */
  89.  
  90. /*
  91.  * Standard terminal interface dispatch table. Most of the fields point into
  92.  * "termio" code.
  93.  */
  94. TERM    term    = {
  95.     NROW-1,
  96.         NROW-1,
  97.         NCOL,
  98.         NCOL,
  99.     MARGIN,
  100.     SCRSIZ,
  101.     NPAUSE,
  102.     openhp,
  103.         closehp,
  104.     hp15kopen,
  105.     hp15kclose,
  106.     gethpkey,
  107.         ttputc,
  108.         hpflush,
  109.         hp15move,
  110.         hp15eeol,
  111.         hp15eeop,
  112.         hp15beep,
  113.         hp15rev,
  114.         hp15cres
  115. #if    COLOR
  116.     , hp15fcol,
  117.     hp15bcol
  118. #endif
  119. };
  120.  
  121. PASCAL NEAR hp15move(row, col)
  122. {
  123.         ttputc(ESC);
  124.         ttputc('&');
  125.         ttputc('a');
  126.         hp15parm(col);
  127.         ttputc('c');
  128.         hp15parm(row);
  129.         ttputc('R');
  130. }
  131.  
  132. PASCAL NEAR hpflush()
  133.  
  134. {
  135.  
  136. }
  137.  
  138. PASCAL NEAR hp15eeol()
  139. {
  140.         ttputc(ESC);
  141.         ttputc('K');
  142. }
  143.  
  144. PASCAL NEAR hp15eeop()
  145. {
  146.         ttputc(ESC);
  147.         ttputc('J');
  148. }
  149.  
  150. PASCAL NEAR hp15rev(status)    /* change the reverse video status */
  151.  
  152. int status;    /* TRUE = on, FALSE = off */
  153.  
  154. {
  155.     ttputc(ESC);
  156.     ttputc('&');
  157.     ttputc('d');
  158.     ttputc((status != FALSE) ? 'B': '@');
  159. }
  160.  
  161. PASCAL NEAR hp15cres()    /* change screen resolution */
  162.  
  163. {
  164.     return(TRUE);
  165. }
  166.  
  167. PASCAL NEAR spal()        /* change pallette register */
  168.  
  169. {
  170.     /*   not here */
  171. }
  172.  
  173. PASCAL NEAR hp15beep()
  174. {
  175.         ttputc(BEL);
  176.         ttflush();
  177. }
  178.  
  179. PASCAL NEAR hp15parm(n)
  180.  
  181. register int    n;
  182.  
  183. {
  184.         register int    q;
  185.  
  186.         q = n/10;
  187.         if (q != 0)
  188.                 hp15parm(q);
  189.         ttputc((n%10) + '0');
  190. }
  191.  
  192. #if    COLOR
  193. PASCAL NEAR hp15fcol()    /* we really can't do colors here, so just ignore it */
  194. {
  195. }
  196.  
  197. PASCAL NEAR hp15bcol()    /* we really can't do colors here, so just ignore it */
  198. {
  199. }
  200. #endif
  201.  
  202. PASCAL NEAR gethpkey()    /* get a key from the HP keyboard while in keycode mode */
  203.  
  204. {
  205.     static int keepflag = 0;    /* kept ahead char flag */
  206.     static int keepchar = 0;    /* kept ehead flag */
  207.     int c;
  208.     int devid;            /* device ID */
  209.     int ctype;            /* type of character gotten */
  210.     int shiftb;            /* state of shift keys */
  211.     int i;
  212.     
  213.     /* if we are in an extended char sequence, finish it */
  214.     if (keepflag != 0) {
  215.         keepflag = 0;
  216.         return(keepchar);
  217.     }
  218.  
  219.     /* grab the next 4 char sequence */
  220. next:    shiftb = ttgetc();
  221.     devid = ttgetc();
  222.     c = ttgetc();
  223.     ttgetc();        /* skip null byte */
  224.     
  225.     /* make sure we are from the keyboard */
  226.     if (devid != 192)
  227.         goto next;
  228.  
  229.     /* if normal ascii, return it */
  230.     if ((shiftb & 0x80) == 0) {
  231.         if (capslock && c >= 'a' && c <= 'z')
  232.             c -= 32;
  233.         return(c);
  234.     }
  235.  
  236.     /* check specifically for the caps lock key */
  237.     if (c == 0x56) {
  238.         capslock = ~capslock;
  239.         goto next;
  240.     }
  241.  
  242.     /* check to see if it needs translation */
  243.     for (i=0; i < NTRANS; i++)
  244.         if (trans[i][0] == c)
  245.             return((int)trans[i][1]);
  246.  
  247.     /* other wise, shove it in the keep char and return the leadin code */
  248.     keepchar = c;
  249.     keepflag = 1;
  250.     return(0);
  251. }
  252.  
  253. PASCAL NEAR openhp()        /* open the HP150 screen for input */
  254.  
  255. {
  256.     strcpy(sres, "NORMAL");
  257.     revexist = TRUE;
  258. }
  259.  
  260. PASCAL NEAR closehp()        /* close the HP150 screen for input */
  261.  
  262. {
  263. }
  264.  
  265. PASCAL NEAR hp15kopen()        /* open the HP150 keyboard for input */
  266.  
  267. {
  268.     /* define key charectoristics with AGIOS call (0, 40) */
  269.     defkey();
  270.  
  271.     /* Turn on RAW mode with MSDOS call 44h */
  272.     rawon();
  273.  
  274.     /* Turn off Control-C checking  MS-DOS 33h */
  275.     ckeyoff();
  276.  
  277.     /* Turn on keycode mode with AGIOS call (0,43) */
  278.     keycon();
  279.  
  280.     /* display the application softkey labels */
  281.     dsplbls();
  282. }
  283.  
  284. PASCAL NEAR hp15kclose()    /* close the HP150 keyboard for input */
  285.  
  286. {
  287.     /* define key charectoristics with AGIOS call (0, 40) */
  288.     undefkey();
  289.     
  290.     /* Turn off RAW mode with MSDOS call 44h */
  291.     rawoff();
  292.  
  293.     /* Turn on Control-C checking  MS-DOS 33h */
  294.     ckeyon();
  295.  
  296.     /* Turn off keycode mode with AGIOS call (0,43) */
  297.     keycoff();
  298. }
  299.  
  300. PASCAL NEAR rawon()    /* put the HP150 keyboard into RAW mode */
  301.  
  302. {
  303.     /* get the IO control info */
  304.  
  305.     r.x.ax = 0x4400;    /* IO ctrl get device information */
  306.     r.x.bx = 0x0001;    /* File handle; 1 for console */
  307.     intdos(&r, &r);        /* go fer it */
  308.  
  309.     r.h.dh = 0;        /* clear high byte for put */
  310.     r.h.dl |= 0x20;        /* set raw bit */
  311.  
  312.     /* and put it back */
  313.  
  314.     r.x.ax = 0x4401;    /* IO ctrl put device information */
  315.     r.x.bx = 0x0001;    /* File handle; 1 for console */
  316.     intdos(&r, &r);        /* go fer it */
  317. }
  318.  
  319. PASCAL NEAR rawoff()    /* put the HP150 keyboard into COOKED mode */
  320.  
  321. {
  322.     /* get the IO control info */
  323.  
  324.     r.x.ax = 0x4400;    /* IO ctrl get device information */
  325.     r.x.bx = 0x0001;    /* File handle; 1 for console */
  326.     intdos(&r, &r);        /* go fer it */
  327.  
  328.     r.h.dh = 0;        /* clear high byte for put */
  329.     r.h.dl &= 0xdf;        /* set raw bit */
  330.  
  331.     /* and put it back */
  332.  
  333.     r.x.ax = 0x4401;    /* IO ctrl put device information */
  334.     r.x.bx = 0x0001;    /* File handle; 1 for console */
  335.     intdos(&r, &r);        /* go fer it */
  336. }
  337.  
  338. PASCAL NEAR ckeyoff()    /* turn control-C trapping off */
  339.  
  340. {
  341.     r.h.ah = 0x33;    /* ctrl-break check */
  342.     r.h.al = 1;    /* set the state of the ctrl-break check */
  343.     r.h.dl = 0;    /* turn it off */
  344.     intdos(&r, &r);
  345. }
  346.  
  347. PASCAL NEAR ckeyon()    /* turn control-C trapping on */
  348.  
  349. {
  350.     r.h.ah = 0x33;    /* ctrl-break check */
  351.     r.h.al = 1;    /* set the state of the ctrl-break check */
  352.     r.h.dl = 1;    /* turn it on */
  353.     intdos(&r, &r);
  354. }
  355.  
  356. #ifdef    unsigned
  357. #undef    unsigned
  358. #endif
  359.  
  360. PASCAL NEAR agios(buf, len)    /* perform an AGIOS call */
  361.  
  362. char *buf;    /* sequence of bytes in command */
  363. int len;    /* length of command in bytes */
  364.  
  365. {
  366.     r.x.ax = 0x4403;    /* I/O ctrl write */
  367.     r.x.bx = 1;        /* console handle */
  368.     r.x.cx = len;        /* buffer length */
  369.     r.x.dx = (unsigned)buf;    /* buffer address */
  370.     return(intdos(&r, &r));    /* do it */
  371. }
  372.  
  373. PASCAL NEAR keycon()    /* turn keycode mode on */
  374.  
  375. {
  376.     static char cmd[] = {43, 0, 1};
  377.  
  378.     return(agios(&cmd[0], 3));
  379. }
  380.  
  381. PASCAL NEAR keycoff()    /* turn keycode mode off */
  382.  
  383. {
  384.     static char cmd[] = {43, 0, 0};
  385.  
  386.     return(agios(&cmd[0], 3));
  387. }
  388.  
  389. PASCAL NEAR defkey()    /* change all special keys to intercept mode */
  390.  
  391. {
  392.     static char cmd[] = {40, 0, 2, 0, 0xfe, 0};
  393.  
  394.     return(agios(&cmd[0], 6));
  395. }
  396.  
  397. PASCAL NEAR undefkey()    /* change all special keys to intercept mode */
  398.  
  399. {
  400.     static char cmd[] = {40, 0, 0, 0, 0xfe, 0};
  401.  
  402.     return(agios(&cmd[0], 6));
  403. }
  404.  
  405. PASCAL NEAR dsplbls()    /* display the application softkey labels on the screen */
  406.  
  407. {
  408.     static char cmd[] = {11, 0};
  409.  
  410.     return(agios(&cmd[0], 2));
  411. }
  412.  
  413. #if    FLABEL
  414. PASCAL NEAR fnclabel(f, n)        /* label a function key */
  415.  
  416. int f,n;    /* default flag, numeric argument */
  417.  
  418. {
  419.     register int status;    /* return status */
  420.     register int i;        /* loop index */
  421.     char lbl[17];    /* returned label contents */
  422.     /* AGIOS command buffer */
  423.     static char cmd[] = {8, 0, 1, 0, 7, 7, 7, 7, 10, 0, 10, 0};
  424.     /*                   code  key#  ptr to      top    bottom
  425.                                      label string  attribute */
  426.     union {        /* union to cast ptr into AGIOS arg string */
  427.         char *ptr;    /* pointer to arg string */
  428.         char cstr[4];
  429.     } ptru;
  430.  
  431.     /* must have a numeric argument */
  432.     if (f == FALSE) {
  433.         mlwrite(TEXT159);
  434. /*                      "%Need function key number" */
  435.         return(FALSE);
  436.     }
  437.  
  438.     /* and it must be a legal key number */
  439.     if (n < 1 || n > 8) {
  440.         mlwrite(TEXT160);
  441. /*                      "%Function key number out of range" */
  442.         return(FALSE);
  443.     }
  444.  
  445.     /* get the string to send */
  446.     status = mlreply(TEXT161, &lbl[0], 17);
  447. /*                       "Label contents: " */
  448.     if (status != TRUE)
  449.         return(status);
  450.  
  451.     /* pad the label out */
  452.     for (i=0; i < 17; i++) {
  453.         if (lbl[i] == 0)
  454.             break;
  455.     }
  456.     for (; i < 16; i++)
  457.         lbl[i] = ' ';
  458.     lbl[16] = 0;
  459.  
  460.     /* set up the parameters */
  461.     cmd[2] = n;            /* function key number */
  462.     ptru.ptr = &lbl[0];        /* set up pointer to label string */
  463. force:    cmd[4] = ptru.cstr[0];
  464.     cmd[5] = ptru.cstr[1];
  465.     cmd[6] = ptru.cstr[2];
  466.     cmd[7] = ptru.cstr[3];
  467.  
  468.     /* and send it out */
  469.     agios(&cmd[0], 12);
  470.     return(TRUE);
  471. }
  472. #endif
  473. #else
  474. PASCAL NEAR h15hello()
  475.  
  476. {
  477. }
  478. #endif
  479.